require 'paperclip'
class Event < ActiveRecord::Base
belongs_to :user
has_many :photos
has_and_belongs_to_many  :locations
validates_presence_of :name, :description
before_create :init_values

# Paperclip
has_attached_file :avatar,
  :styles => {
    :thumb=> "100x100#",
    :small  => "150x150>",
    :medium => "300x300>",
    :large =>   "400x400>" }
	def init_values
		self.good_rating = 0
		self.bad_rating = 0
		true
	end
	def rating
		if ((self.good_rating + self.bad_rating) > 0)
			((self.good_rating - self.bad_rating)/(self.good_rating + self.bad_rating)) * 10
		else 
			"No tiene puntuación"
		end
	end
end
